home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Original Shareware 1.1
/
The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso
/
6
/
strfile.zip
/
STRFILE.C
next >
Wrap
Text File
|
1986-10-14
|
3KB
|
143 lines
/* str file name functions (for Lattice 3.0 port to MSC 4.0) */
/* ------------------------------------------------------------ */
/* copyright 1986: */
/* Nourse Gregg & Browne, Inc. */
/* 1 Horizon Road. #612 */
/* Fort Lee, NJ 07024 */
/* */
/* ------------------------------------------------------------ */
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#define ZIP '\0'
/* ------------------------------------------------------------ */
/* strsfn - split filename into components */
void strsfn(file,drive,path,node,ext)
char *file; /* input: the whole file name */
char *drive; /* output: the drive */
char *path; /* output: the sub-directory path */
char *node; /* output: the file's base name */
char *ext; /* output: the file's extension */
{
char *p;
char fn[64];
strncpy(fn,file,63);
p=strrchr(fn,'.'); /* find start of extension */
if (p==NULL) *ext=ZIP;
else
{
*p=ZIP;
strcpy(ext,p+1);
}
p=strrchr(fn,'\\'); /* find end of path */
if (p==NULL)
{
*path=ZIP;
p=strrchr(fn,':');
if (p==NULL)
{
strcpy(node,fn);
*drive=ZIP;
}
else
{
strcpy(node,p+1);
*(p+1)=ZIP;
strcpy(drive,fn);
}
}
else
{
*p=ZIP;
strcpy(node,p+1);
p=strrchr(fn,':');
if (p==NULL)
{
strcpy(path,fn);
*drive=ZIP;
}
else
{
strcpy(path,p+1);
*(p+1)=ZIP;
strcpy(drive,fn);
}
}
}
/* ------------------------------------------------------------ */
/* strmfe - make filename with new extension */
void strmfe(newname,oldname,ext)
char *newname; /* output: the new file name */
char *oldname; /* input: the old file name */
char *ext; /* input: the new extension */
{
char *p;
strcpy(newname,oldname);
p=strrchr(newname,'.');
if (p==NULL)
{
strcat(newname,".");
strcat(newname,ext);
}
else
{
strcpy(p+1,ext);
}
}
/* ------------------------------------------------------------ */
/* strmfn - make filename from components */
void strmfn(file,drive,path,node,ext)
char *file; /* output: the whole file name */
char *drive; /* input: the drive (or NULL) */
char *path; /* input: the directory path (or NULL) */
char *node; /* input: the file's base name */
char *ext; /* input: the file's extension (or NULL) */
{
int i;
*file='\0';
if (drive!=NULL)
{
strcat(file,drive);
if (file[1]!=':') strcat(file,":");
}
if (path!=NULL)
{
strcat(file,path);
i=strlen(file);
if (file[i-1]!='\\')
{
file[i]='\\';
file[i+1]='\0';
}
}
if (node!=NULL) strcat(file,node);
if (ext!=NULL)
{
strcat(file,".");
strcat(file,ext);
}
}